<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-row>
        <el-col :span="12">
          <el-form-item label="工号" prop="usercode" :rules="rules.validateRequire">
            <tl-ref-user v-model="model.usercode" :initDisplayData.sync="model.username" dataType="code" @confirm="refUserConfirm" :singleSelect="true"></tl-ref-user>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="部门名称">
            <el-select v-model="createdepart" placeholder="请选择部门名称" filterable clearable multiple>
              <el-option v-for="item in codeModel.deptCommonCodeList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" maxlength="1000" show-word-limit :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
import { validateNull } from '@tapui/utils/validate'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: {},
  data() {
    return {
      moduleTitle: 'PMO标准化人选档案',
      urlPrefix: '/mpm/pMOStandardizationRecord/',
      url: {
        // 额外的url
      },
      createdepart: []
    }
  },
  methods: {
    loaded() {
      // 页面加载完毕执行
      this.createdepart = []
      if (!validateNull(this.model.chargedeptcommoncode)) {
        this.$set(this, 'createdepart', this.model.chargedeptcommoncode.split(','))
      }
    },
    refUserConfirm(selectionRow) {
      console.log(selectionRow[0])
      this.$set(this.model, 'username', selectionRow[0].name)
      this.$set(this.model, 'usercode', selectionRow[0].code)
    },
    // 部门名称多选框
    // doQueryConcatCreateDepart(data) {
    //   if (data.length > 0) {
    //     this.$set(this.model, 'chargedeptcommoncode', data.join(','))
    //   } else {
    //     this.$set(this.model, 'chargedeptcommoncode', null)
    //   }
    // },
    // 审批之前赋值chargedeptcommoncode
    beforeSubmit() {
      if (this.createdepart.length > 0) {
        this.$set(this.model, 'chargedeptcommoncode', this.createdepart.join(','))
      } else {
        this.$set(this.model, 'chargedeptcommoncode', null)
      }
      return true
    }
  }
}
</script>

